import Vue from 'vue';

export default {
	state: {
		isLogin: false,
		count: 0
	},
	getters: {
		isLogin: state => state.isLogin,
		count: state => state.count,
	},
	mutations: {
		// 由于mutation必须同步执行的限制，不方便实现复杂的功能。不过Actions不受约束！我们可以在 它内部执行异步操作
		addmu(state) {
			state.count++
		},
		lessmu(state) {
			state.count--
		},
		isLogin(state, res) {
			state.isLogin = res.isLogin
		}
	},
	actions: {
		addac({
			commit
		}) {
			commit('addmu')
		},
		lessac({
			commit
		}) {
			commit('lessmu')
		},
		isLogin({
			commit
		}, res) {
			commit('isLogin', res)
		},
		// isLogin(state, that) {
		//   return new Promise((resolve, reject) => {
		//     that.$uc.isLogin().then(function () {
		//       const account = that.$uc.getCurrentAccount();
		//       if (account) {
		//         account.getAccountInfo().then((accountInfo) => {
		//           state.state.userInfo = accountInfo;
		//           resolve();
		//         });
		//       } else {
		//         reject();
		//       }
		//     });
		//   });
		// },
	},
};
